package com.lh0811.forge.pserv.uacs.server.adapter.controller;

import com.github.pagehelper.PageInfo;
import com.lh0811.forge.dependency.basic_web.constant.AuthConstant;
import com.lh0811.forge.dependency.basic_web.response.ServerResponse;
import com.lh0811.forge.dependency.security.client.component.annotation.HasUrl;
import com.lh0811.forge.pserv.uacs.api.param.UacsDataRuleCreateParam;
import com.lh0811.forge.pserv.uacs.api.param.UacsDataRuleQueryListParam;
import com.lh0811.forge.pserv.uacs.api.param.UacsDataRuleQueryPageParam;
import com.lh0811.forge.pserv.uacs.api.param.UacsDataRuleUpdateParam;
import com.lh0811.forge.pserv.uacs.api.vo.UacsDataRuleVo;
import com.lh0811.forge.pserv.uacs.server.service.PlateDataRuleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Tag(name = "权限中心-平台数据规则管理")
@RestController
@RequestMapping("/forge/plate/v1/uacs/data_rule")
public class OpmsPlateDataRuleController {

    @Resource
    private PlateDataRuleService plateDataRuleService;


    // 创建数据规则
    @HasUrl
    @PutMapping("/create")
    @Operation(summary = "创建数据规则", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse dataRuleCreate(@RequestBody @Valid UacsDataRuleCreateParam param) throws Exception {
        plateDataRuleService.dataRuleCreate(param);
        return ServerResponse.createBySuccess();
    }

    // 删除数据规则
    @HasUrl
    @DeleteMapping("/delete/{dataRuleId}")
    @Operation(summary = "删除数据规则", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse dataRuleDelete(@PathVariable(value = "dataRuleId") Long dataRuleId) throws Exception {
        plateDataRuleService.dataRuleDelete(dataRuleId);
        return ServerResponse.createBySuccess();
    }

    // 修改数据规则
    @HasUrl
    @PostMapping("/update")
    @Operation(summary = "修改数据规则", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse dataRuleUpdate(@RequestBody @Valid UacsDataRuleUpdateParam param) throws Exception {
        plateDataRuleService.dataRuleUpdate(param);
        return ServerResponse.createBySuccess();
    }

    // 查询数据规则(分页)
    @HasUrl
    @GetMapping("/query/page")
    @Operation(summary = "查询数据规则（分页）", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse<PageInfo<UacsDataRuleVo>> dataRuleQueryPage(@ParameterObject @Valid UacsDataRuleQueryPageParam param) throws Exception {
        return ServerResponse.createBySuccess(plateDataRuleService.dataRuleQueryPage(param));
    }


    // 查询数据规则(不分页)
    @HasUrl
    @GetMapping("/query/list")
    @Operation(summary = "查询数据规则（不分页）", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse<List<UacsDataRuleVo>> dataRuleQueryList(@ParameterObject @Valid UacsDataRuleQueryListParam param) throws Exception {
        return ServerResponse.createBySuccess(plateDataRuleService.dataRuleQueryList(param));
    }


}
